package d20chat;


public class MapSquare {
	private int height;
	private String content;
	private Terrain terrain;
	
//	Type of object in square
//	0 = normal (NPC/objects/etc)
//	1 = PC
//	2 = enemy
	private int type = 0;
	
	public MapSquare()
	{
		this(new Terrain(), 0, "", 0);
	}
	
	public MapSquare(Terrain t, String c)
	{
		this(t, 0, c, 0);
	}
	
	public MapSquare(Terrain t, int h, String c)
	{
		this(t, h, c, 0);
	}
	
	public MapSquare(Terrain t, int h, String c, int type)
	{
		height = h;
		content = c;
		terrain = t;
		this.type = type;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getHeight() {
		return height;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getContent() {
		return content;
	}

	public void setTerrain(Terrain terrain) {
		this.terrain = terrain;
	}

	public Terrain getTerrain() {
		return terrain;
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getType() {
		return type;
	}
	
	public String toString()
	{
		return "H"+height+"C"+content+"-T"+type+"T"+terrain;
	}
	
	public static MapSquare parse(String s)
	{
		System.out.println(s);
		int h = Integer.parseInt(s.substring(1, s.indexOf('C')));
		String c = s.substring(s.indexOf('C')+1, s.indexOf("-T"));
		int t = Integer.parseInt(s.substring(s.indexOf("-T")+2, s.indexOf("-T")+3));
		Terrain tt = Terrain.parse(s.substring(s.indexOf("-T")+2));
		return new MapSquare(tt, h, c, t);
	}
}
